package com.hycc.base;

import lombok.SneakyThrows;
import java.util.concurrent.TimeUnit;

public class VolatileDemo {
    private volatile static int num = 0;

    @SneakyThrows
    public static void main(String[] args) {

        new Thread(()->{
            while(num==0){
                //这个不能写，不然代码走不下去
                //System.out.println(Thread.currentThread().getName()+" going");
            }
        }).start();

        TimeUnit.SECONDS.sleep(1);

        num=1;
        System.out.println(num);
    }
}
